using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ShivamEMR.Model.Domain.CRMDomain;
using ShivamEMR.Model.DataInterfaces.CRMDataInterf;
using ShivamEMR.Model;

namespace ShivamEMR.Web.Areas.CRM.Controllers
{   
    public class AssignmentGroupController : Controller
    {
		private readonly IAssignmentGroupRepository assignmentgroupRepository;

		// If you are using Dependency Injection, you can delete the following constructor
        public AssignmentGroupController()// : this(new AssignmentGroupRepository())
        {
            this.assignmentgroupRepository = Registry.RepositoryFactory.GetAssignmentGroupRepository();
        }

        public AssignmentGroupController(IAssignmentGroupRepository assignmentgroupRepository)
        {
			this.assignmentgroupRepository = assignmentgroupRepository;
        }

        //
        // GET: /AssignmentGroup/

        public ViewResult Index()
        {
            return View(assignmentgroupRepository.All);//Including(assignmentgroup => assignmentgroup.Parent, assignmentgroup => assignmentgroup.Children, assignmentgroup => assignmentgroup.Assignments));
        }

        //
        // GET: /AssignmentGroup/Details/5

        public ViewResult Details(int id)
        {
            return View(assignmentgroupRepository.Find(id));
        }

        //
        // GET: /AssignmentGroup/Create

        public ActionResult Create()
        {
			ViewBag.PossibleParents = assignmentgroupRepository.All;
            return View();
        } 

        //
        // POST: /AssignmentGroup/Create

        [HttpPost]
        public ActionResult Create(AssignmentGroup assignmentgroup)
        {
            if (ModelState.IsValid) {
                assignmentgroupRepository.Create(assignmentgroup);
                assignmentgroupRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossibleParents = assignmentgroupRepository.All;
				return View();
			}
        }
        
        //
        // GET: /AssignmentGroup/Edit/5
 
        public ActionResult Edit(int id)
        {
			ViewBag.PossibleParents = assignmentgroupRepository.All;
             return View(assignmentgroupRepository.Find(id));
        }

        //
        // POST: /AssignmentGroup/Edit/5

        [HttpPost]
        public ActionResult Edit(AssignmentGroup assignmentgroup)
        {
            if (ModelState.IsValid) {
                assignmentgroupRepository.Update(assignmentgroup);
                assignmentgroupRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossibleParents = assignmentgroupRepository.All;
				return View();
			}
        }

        //
        // GET: /AssignmentGroup/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View(assignmentgroupRepository.Find(id));
        }

        //
        // POST: /AssignmentGroup/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            var a = assignmentgroupRepository.Find(id);
            assignmentgroupRepository.Delete(a);
            assignmentgroupRepository.Save();

            return RedirectToAction("Index");
        }
    }
}

